//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.awspaas.user.apps.publicservice.util;

import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class SpjlUtils {
    public SpjlUtils() {
    }

    public static String getSpjl(int i, RowMap rm) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        StringBuffer sbsb = new StringBuffer();
        sbsb.append("<tr id='tr" + i + "'>");
        sbsb.append("<td align='center'>" + i + "</td>");
        String taskid = String.valueOf(rm.get("ID"));
        String processid = rm.getString("PROCESSINSTID");
        ProcessInstance processInstance = SDK.getProcessAPI().getInstanceById(processid);
        boolean isenda = processInstance.isEnd();
        String tabel = null;
        if (isenda) {
            tabel = "WFH_COMMENT";
        } else {
            tabel = "WFC_COMMENT";
        }

        System.out.println("taksid:" + taskid);
        RowMap rowMap = DBSql.getMap("SELECT ACTIVITYNAME FROM " + tabel + " WHERE TASKINSTID=?", new Object[]{taskid});
        System.out.println(rowMap);
        String ACTIVITYNAME = DBSql.getString("SELECT ACTIVITYNAME FROM " + tabel + " WHERE TASKINSTID=?", new Object[]{taskid});
        System.out.println("ACTIVITYNAME:" + ACTIVITYNAME);
        System.out.println(rm);
        String tit = rm.getString("TASKTITLE");
        String actname = tit.substring(tit.lastIndexOf("(") + 1, tit.lastIndexOf(")"));
        if (ACTIVITYNAME == null || ACTIVITYNAME.equals("")) {
            ACTIVITYNAME = actname;
        }

        sbsb.append("<td align='center'>" + ACTIVITYNAME + "</td>");
        String uid = rm.getString("TARGET");
        System.out.println(""+uid);
        SDK.getLogAPI().consoleInfo("当前的用户的uid======="+uid);
        String uname = null;
        String depname = null;
        String rolename = null;

        try {
            uname = SDK.getORGAPI().getUser(uid).getUserName();
            depname = SDK.getORGAPI().getDepartmentByUser(uid).getName();
            rolename = SDK.getORGAPI().getRoleByUser(uid).getName();
        } catch (Exception var22) {
            var22.printStackTrace();
        }

        sbsb.append("<td align='center'>");
        sbsb.append("<span userid='"+uid+"' class='awsui-user-profile owner'>" + uname + "</span>/" + depname + "(" + rolename + ")");
        sbsb.append("</td>");
        String endTime = "";

        try {
            endTime = sdf.format(SDK.getTaskAPI().getInstanceById(rm.getString("ID")).getEndTime());
        } catch (Exception var21) {
            endTime = sdf.format(SDK.getTaskAPI().getInstanceById(rm.getString("ID")).getBeginTime());
            var21.printStackTrace();
        }

        sbsb.append("<td align='center'>" + endTime + "</td>");
        String actionName = DBSql.getString("SELECT ACTIONNAME FROM " + tabel + " WHERE TASKINSTID=?", new Object[]{rm.getString("ID")});
        if (actionName.equals("")) {
            boolean is = SDK.getTaskAPI().isClose(rm.getString("ID"));
            if (is) {
                actionName = "已完成";
            } else {
                actionName = "正在办理";
            }
        }

        System.out.println("actionName:" + actionName);
        sbsb.append("<td align='center'>" + actionName + "</td>");
        SDK.getProcessAPI().getInstanceById(rm.getString("PROCESSINSTID")).isEnd();
        String msg = DBSql.getString("SELECT MSG FROM " + tabel + " WHERE TASKINSTID=?", new Object[]{rm.getString("ID")});
        System.out.println("msg:" + msg);
        if (null != msg && !"null".equals(msg) && !"".equals(msg)) {
            sbsb.append("<td>" + msg + "<span id='DOM_AWS_OPINION_MSG_Files0'></span></td></tr>");
        } else {
            sbsb.append("<td><span id='DOM_AWS_OPINION_MSG_Files0'></span></td></tr>");
        }

        return sbsb.toString();
    }

    public static String getSpjlMobile(UserContext uc, int i, List<RowMap> rowmaps, String bindid, String type) throws ParseException {
        StringBuffer sbsb = new StringBuffer();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        boolean flag = SDK.getProcessAPI().getInstanceById(bindid).isEnd();
        RowMap item = (RowMap)rowmaps.get(i);
        boolean a = SDK.getTaskAPI().isClose(item.getString("ID"));
        String status = "";
        String uid = item.getString("TARGET");
        String tx = SDK.getPortalAPI().getUserPhoto(uc, uid);
        String uname = SDK.getRuleAPI().executeAtScript("@username(" + uid + ")");
        String actname = item.getString("TASKTITLE");
        int index1 = actname.lastIndexOf("(");
        int index2 = actname.lastIndexOf(")");
        String d1 = item.getString("BEGINTIME");
        String d2 = item.getString("ENDTIME");
        if (d2.equals("")) {
            d2 = "";
        } else {
            d2 = sdf.format(sdf.parse(d2));
        }

        String ACTIVITYNAME = actname.substring(index1 + 1, index2);
        if (i == 0) {
            if (a) {
                status = "提交";
            } else {
                status = "正在办理";
            }

            sbsb.append("<tr style='width: 100%'>");
            sbsb.append("<td class='mui-check-td-left' style='border-color:'>");
            sbsb.append(" <img class='mui-media-object mui-pull-left mui-media-object-img'\n                    src='" + tx + "'>");
            sbsb.append("<div class='mui-check-td-left-text' align='center'>");
            sbsb.append("<span userid='" + uid + "' class='awsui-user-profile owner' style='font-weight:800'>" + uname + "</span>");
            sbsb.append(" </div></td>");
            sbsb.append("<td class='mui-check-td-right'>");
            sbsb.append(" <img src='../apps/_bpm.portal/img/mobileui/circle-green.png'  class='mui-task-option-img'>");
            sbsb.append("<div><div class='mui-msg-title'  style='font-weight:800'>");
            sbsb.append(ACTIVITYNAME + "(" + status + ")");
            sbsb.append("</div>");
            sbsb.append(sdf.format(sdf.parse(d1)) + "<br />");
            sbsb.append("</div></td>");
            sbsb.append(" </tr>");
        }
        if(rowmaps.size() > 1){
            if (i > 0 & i < rowmaps.size() - 1) {
            if (a) {
                status = "已完成";
            } else {
                status = "正在办理";
            }

            sbsb.append("<tr style='width: 100%'>");
            sbsb.append("<td class='mui-check-td-left' style='border-color:'>");
            sbsb.append(" <img class='mui-media-object mui-pull-left mui-media-object-img'\n                    src='" + tx + "'>");
            sbsb.append("<div class='mui-check-td-left-text' align='center'>");
            sbsb.append("<span userid='" + uid + "' class='awsui-user-profile owner'  style='font-weight:800'>" + uname + "</span>");
            sbsb.append(" </div></td>");
            sbsb.append("<td class='mui-check-td-right'>");
            sbsb.append(" <img src='../apps/_bpm.portal/img/mobileui/circle-green.png'  class='mui-task-option-img'>");
            sbsb.append("<div><div class='mui-msg-title'  style='font-weight:800'>");
            sbsb.append(ACTIVITYNAME + "(" + status + ")");
            sbsb.append("</div>");
            sbsb.append("接收时间：" + sdf.format(sdf.parse(d1)) + "<br />办理时间：" + d2);
            sbsb.append("</div></td>");
            sbsb.append(" </tr>");
        }

            if (i == rowmaps.size() - 1) {
            if (a) {
                status = "已完成";
            } else {
                status = "正在办理";
            }

            if (!flag) {
                sbsb.append("<tr style='width: 100%'>");
                sbsb.append("<td class='mui-check-td-left' style='border-color:' >");
                sbsb.append(" <img class='mui-media-object mui-pull-left mui-media-object-img'\n                    src='" + tx + "'>");
                sbsb.append("<div class='mui-check-td-left-text' align='center'>");
                sbsb.append("<span userid='" + uid + "' class='awsui-user-profile owner' style='font-weight:800'>" + uname + "</span>");
                sbsb.append(" </div></td>");
                sbsb.append("<td class='mui-check-td-right'>");
                sbsb.append(" <img src='../apps/_bpm.portal/img/mobileui/circle-green.png'  class='mui-task-option-img'>");
                sbsb.append("<div><div class='mui-msg-title' style='font-weight:800'>");
                sbsb.append(ACTIVITYNAME + "(" + status + ")");
                sbsb.append("</div>");
                sbsb.append("接收时间：" + sdf.format(sdf.parse(d1)) + "<br />办理时间：" + d2);
                sbsb.append("</div></td>");
                sbsb.append(" </tr>");
            } else {
                sbsb.append("<td class='mui-check-td-left' style='border-color:'>");
                sbsb.append(" <img class='mui-media-object mui-pull-left mui-media-object-img'\n                    src='" + tx + "'>");
                sbsb.append("<div class='mui-check-td-left-text' align='center'>");
                sbsb.append("<span userid='" + uid + "' class='awsui-user-profile owner'  style='font-weight:800'>" + uname + "</span>");
                sbsb.append(" </div></td>");
                sbsb.append("<td class='mui-check-td-right'>");
                sbsb.append(" <img src='../apps/_bpm.portal/img/mobileui/circle-green.png'\n                    class='mui-task-option-img'>");
                sbsb.append("<div><div class='mui-msg-title'  style='font-weight:800'>");
                sbsb.append(ACTIVITYNAME + "(" + status + ")");
                sbsb.append("</div>");
                sbsb.append("接收时间：" + sdf.format(sdf.parse(d1)) + "<br />办理时间：" + d2);
                sbsb.append(" </tr>");
                sbsb.append("<tr style='width: 100%'>");
                sbsb.append("<td class='mui-check-td-left' style='border-color:'>");
                sbsb.append("<div class='mui-check-td-left-text' align='center'>");
                sbsb.append(" </div></td>");
                sbsb.append("<td class='mui-check-td-right'>");
                sbsb.append(" <img src='../apps/_bpm.portal/img/mobileui/circle-green.png'      class='mui-task-option-img'>");
                sbsb.append("<div><div class='mui-msg-title'  style='font-weight:800;'>");
                sbsb.append("结束");
                sbsb.append("</div>");
                Timestamp b = SDK.getProcessAPI().getInstanceById(bindid).getEndTime();
                sbsb.append("结束时间：" + sdf.format(sdf.parse(String.valueOf(b))) + "<br />");
                sbsb.append("</div></td>");
                sbsb.append(" </tr>");
            }
        }

        }
        System.out.println(sbsb.toString() + "\n");
        return sbsb.toString();
    }

    public static String timePastTenSecond(String otime) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date dt = sdf.parse(otime);
            Calendar newTime = Calendar.getInstance();
            newTime.setTime(dt);
            newTime.add(13, 1);
            Date dt1 = newTime.getTime();
            String retval = sdf.format(dt1);
            return retval;
        } catch (Exception var6) {
            var6.printStackTrace();
            return null;
        }
    }
}
